package com.pi.config;




import com.pi.core.exchange.vo.CommonNameRegistryService;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.edi.sap.common.SapWasXcmgExchangeConstants;
import com.pi.pro.xcmg.am.was.edi.sap.service.DeliveryNoteServiceProxy;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpclientProxy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 *
 */
@Configuration
public class SapWmsClientExchangeConfig {

    //
    private Map<String, Map<String, String>> fullSapWasLocationMapping=new HashMap<>();


    @Value("${erp.api.was.active}")
    private boolean sapInterfaceActive=false;

/**==================================================================================================================**/
//  WH101/
/**==================================================================================================================**/

    @Value("${erp.api.was.wh101.code}")
    private String sapWh101ServiceCode;

    @Value("${erp.api.was.wh101.warehousecode}")
    private String sapWh101Warehousecode;

    /**
    @Value("${erp.api.was.wh101.token}")
    private String sapWh101Token;
    **/

    /**
     * DELIVERY
     */
    @Value("${erp.api.was.wh101.delivery.client.code}")
    private String sapDeliveryWh101ClientCode;

    @Value("${erp.api.was.wh101.delivery.func.load.url}")
    private String sapDeliveryLoadWh101PostAccessUrl;

    @Value("${erp.api.was.wh101.delivery.func.trans.url}")
    private String sapDeliveryTransWh101PostAccessUrl;




/**==================================================================================================================**/
//  all

    public boolean interfaceActive() {
        return sapInterfaceActive;
    }

    /**==================================================================================================================**/



    @Bean
    public CommonNameRegistryService sapNameRegistryService(){
        CommonNameRegistryService nameRegistryService = new CommonNameRegistryService(SapWasXcmgExchangeConstants.SAP_ENDPOINT_NAMESPACE);
        nameRegistryService.clientnMapping(XcmgAmConstants.clients);
        nameRegistryService.orgnizationMapping(XcmgAmConstants.organizations);
        return nameRegistryService;
    }





/**==================================================================================================================**/
//  WH101
/**==================================================================================================================**/

    /**********************************************/
    //** DELIVERY
    /**********************************************/
    @Bean
    public HttpAccessUrl sapDeliveryLoadWh101PostAccessUrl(){
        HttpAccessUrl accessUrl=new HttpAccessUrl();
        accessUrl.setUrl(this.sapDeliveryLoadWh101PostAccessUrl);
        return accessUrl;
    }

    @Bean
    public HttpAccessUrl sapDeliveryTransWh101PostAccessUrl(){
        HttpAccessUrl accessUrl=new HttpAccessUrl();
        accessUrl.setUrl(this.sapDeliveryTransWh101PostAccessUrl);
        return accessUrl;
    }

    @Bean
    public HttpclientProxy sapDeliveryWh101Client(){
        HttpclientProxy client=new HttpclientProxy(this.sapDeliveryWh101ClientCode);
        return client;
    }

    @Bean
    public DeliveryNoteServiceProxy sapWasDeliveryWh101ServiceProxy(){
        DeliveryNoteServiceProxy proxy=new DeliveryNoteServiceProxy();
        proxy.setCategory(this.sapWh101ServiceCode);
        proxy.setCode(this.sapWh101ServiceCode+this.sapDeliveryWh101ClientCode);
        proxy.setSapDeliveryClient(this.sapDeliveryWh101Client());
        //proxy.setToken(this.xwmsWh101Token);
        proxy.setSapDeliveryLoadPostAccessUrl(this.sapDeliveryLoadWh101PostAccessUrl());
        proxy.setSapDeliveryTransPostAccessUrl(this.sapDeliveryTransWh101PostAccessUrl());
        this.sapNameRegistryService().register(proxy);
        return proxy;
    }



}
